#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;

void test()
{
    deque<int> de;
    de.push_back(1);
    sort(de.begin(), de.end()); // 默认升序
}

using namespace std;

void printVector(const vector<int> &v)
{
    for (vector<int>::const_iterator it = v.begin(); it != v.end(); it++)
    {
        cout << *it << " ";
    }
    cout << endl;
}

void printVector1(vector<int> &v)
{
    for (size_t i = 0; i < v.size(); i++)
    {
        cout << v[i] << " ";
    }

    cout << endl;
}

void isEmpty(const vector<int> &v)
{
    if (v.empty())
    {
        cout << "v empty" << endl;
    }
    else
    {
        cout << "v not empty" << endl;
    }
}

void test01()
{
    vector<int> v;
    vector<int> v2(10);
    isEmpty(v);
    int n_size = v.size();
    int n_capacity = v.capacity();
    cout << "size:" << n_size << "  capacity: " << n_capacity << endl;

    for (size_t i = 0; i < 10; i++)
    {
        v.push_back(i * 10);
    }
    printVector(v);

    v.pop_back();
    printVector(v);

    v.insert(v.begin(), 1000);
    printVector(v);
    v.insert(v.begin(), 2, 100);
    printVector(v);
    v.erase(v.begin());
    printVector(v);
    v.erase(v.begin(), v.end() - 3);
    printVector1(v);

    // v.clear();
    // printVector(v);

    cout << v.front() << endl;
    cout << v.back() << endl;

    cout << v.at(0) << endl;
    cout << v.at(1) << endl;
    cout << v.at(2) << endl;

    vector<double> v1;
    v1.reserve(10000);
    int num; // record remalloc num
    double *p = nullptr;
    for (size_t i = 0; i < 10000; i++)
    {
        v1.push_back(i + 20);
        if (p != &v1[0])
        {
            p = &v1[0];
            num++;
        }
    }

    // swap + resize
    cout << v1.capacity() << "   " << v1.size() << endl;
    v1.resize(10); // resize
    cout << v1.capacity() << "   " << v1.size() << endl;
    vector<double>(v1).swap(v1); // swap
    cout << v1.capacity() << "   " << v1.size() << endl;
    cout << "num is : " << num << endl;

    // cout << v.at(3) << endl;

    // isEmpty(v);
    // n_size = v.size();
    // n_capacity = v.capacity();
    // cout << "size:" << n_size << "  capacity: " << n_capacity << endl;

    // v.resize(10, 20);
}

void test02()
{
    vector<int> v;
    // v.reserve(10);
    // v.resize(10);
    // v.at(8) = 2;
    v.push_back(2);
    vector<int>vee = vector<int>(v);
    cout << v.size() << "  " << v.back() << endl;
}

void test03()
{
    unsigned char c = 255;
    char c1 = 128;
    cout << "c = " << int(c) << endl;
    cout << "c1 = " << int(c1) << endl;

    cout << "c = " <<unsigned(c) << endl;
    cout << "c1 = " <<unsigned(c1) << endl;
    // printf("%c", c);
}

int main()
{
    test02();
    return 0;
}